package huoye.shops.huoye.user.presenter;


import android.os.CountDownTimer;

import com.codeideology.android.rpc.BaseJsonRequestCallback;
import com.codeideology.android.utils.StringUtils;

import java.util.List;

import huoye.shops.MainActivity;
import huoye.shops.R;
import huoye.shops.base.BasePresenter;
import huoye.shops.base.MineBaseJsonRequestCallback;
import huoye.shops.base.UserManager;
import huoye.shops.common.model.SMSCoder;
import huoye.shops.huoye.user.model.AreaInfo;
import huoye.shops.huoye.user.model.CityData;
import huoye.shops.huoye.user.model.SelectCityData;
import huoye.shops.huoye.user.model.UpdateInfo;
import huoye.shops.huoye.user.model.User;
import huoye.shops.huoye.user.network.UserService;
import huoye.shops.huoye.user.view.ILoginView;
import huoye.shops.huoye.user.view.ISelectCityView;
import huoye.shops.utils.StockUtils;


/**
 * Created by uesr on 2017/7/19.
 */

public class SelectCityPresenter extends BasePresenter<ISelectCityView> {

    private UserService mService;




    //获取代理商接口地址信息
    public void selectCity(String province,String city,String district){
        //   view.showProcessingIndicator();
        mService.selectCity(province,city,district,new MineBaseJsonRequestCallback<SelectCityData>(SelectCityData.class) {

            @Override
            public void onSuccess(SelectCityData selectCityData) {
                super.onSuccess(selectCityData);
                if(!StringUtils.isNotEmpty(selectCityData.getApiUrl())){
                    view.makeToast("该区域未申请代理或过期");
                    return;
                }else {
                    UserManager.getInstance().removeUrl();
                    UserManager.getInstance().removeImageUrl();
                    view.getUrl(selectCityData);
                }

            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }


    //获取代理商接口地址信息
    public void getAreaInfo(String ftype,String areaname){
        mService.getAreaInfo(ftype,areaname,new MineBaseJsonRequestCallback<CityData>(CityData.class) {
            @Override
            public void onSuccess(CityData cityData) {
                super.onSuccess(cityData);
                view.getAreaData(cityData.getAreaInfos());
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }


    @Override
    public void onStart() {
       mService =  new UserService();
    }
}
